import { useCascaderAreaData } from '@/plugins/area-data'

export interface CascaderOption {
  label: string
  value: string
  children?: CascaderOption[]
}

export function useColPickerData() {
  const colPickerData: CascaderOption[] = useCascaderAreaData()
  function findChildrenByCode(data: CascaderOption[], code?: string): CascaderOption[] | null {
    if (!code) {
      return data
    }
    for (const item of data) {
      if (item.value === code) {
        return item.children || null
      }
      if (item.children) {
        const childrenResult = findChildrenByCode(item.children, code)
        if (childrenResult) {
          return childrenResult
        }
      }
    }
    return null
  }
  return { colPickerData, findChildrenByCode }
}
